<?php
header("content-Type: text/html; charset=utf-8");
$conn = @mysqli_connect("localhost","root","","abcd");
if (!$conn){
    die("连接数据库失败：" . mysqli_error());
}
$title= $_POST['title'];
$patch = $_POST['content'];
$content = str_replace("","<br />",$patch);
session_start();
$user =$_SESSION['username'];
$jifen="select jifen from user WHERE username='$user'";
$jifen=mysqli_query($conn,$jifen);
$jifen=mysqli_fetch_array($jifen);
$me=$_GET['ad'];
if($jifen[0]>=10)
{

    /*$jishu="select * from message";
    $jishu=mysqli_query($conn,$jishu);
    $jishu=mysqli_num_rows($jishu);
    $jishu=$jishu+1;
    */
    //session_start();
    //$user =$_SESSION['username'];

    $sql = "insert into message(title,user,content,sheji,type) values ('$title','$user','$content',0,'$me')";
    mysqli_query($conn,$sql);

    $jifen="select jifen from user where username='$user'";
    $jifen=mysqli_query($conn,$jifen);
    $jifen=mysqli_fetch_row($jifen);
    $jifen=$jifen[0]+1;
    $jifenTwo="update user set jifen=jifen+1 WHERE username='$user'";
    mysqli_query($conn,$jifenTwo);
    echo "欢迎回来".$user;
    echo "<script language='JavaScript'>alert('发帖成功，增加一个积分，您当前的积分为{$jifen}');location.href='shouye.php';</script>";

}
else {
    echo "<script language='JavaScript'>alert('您当前的积分不足,发布失败');location.href='shouye.php';</script>";
}
?>


